﻿    <ul>
        @if (Model.PageCount <= 5)
        {
            for (int i = 1; i <= Model.PageCount; i++)
            {
                if (i == Model.PageIndex)
                {
            <li class="active"><span>@i</span></li>
                }
                else
                {
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, i.ToString()))">@i</a></li>
                }
            }
        }
        else
        {
            if (Model.PageIndex <= 3)
            {
                for (int i = 1; i <= Model.PageIndex; i++)
                {
                    if (i == Model.PageIndex)
                    {
            <li class="active"><span>@i</span></li>
                    }
                    else
                    {
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, i.ToString()))">@i</a></li>
                    }
                }
            <li><span>...</span></li>    
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, Model.PageCount.ToString()))">@Model.PageCount</a></li>        
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, (Model.PageIndex + 1).ToString()))" title="next page">>></a></li>        
            }

            else if (Model.PageIndex >= Model.PageCount - 2)
            {
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, (Model.PageIndex - 1).ToString()))" title="pre page"><<</a></li>        
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, "1"))">1</a></li>        
            <li><span>...</span></li>    
                for (int i = Model.PageCount - 2; i <= Model.PageCount; i++)
                {
                    if (i == Model.PageIndex)
                    {
            <li class="active"><span>@i</span></li>
                    }
                    else
                    {
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, i.ToString()))">@i</a></li>
                    }
                }
            }
            else
            {
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, (Model.PageIndex - 1).ToString()))" title="pre page"><<</a></li>        
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, "1"))">1</a></li>        
            <li><span>...</span></li> 
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, (Model.PageIndex - 1).ToString()))">@(Model.PageIndex - 1)</a></li>
            <li class="active"><span>@Model.PageIndex</span></li>
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, (Model.PageIndex + 1).ToString()))">@(Model.PageIndex + 1)</a></li>
            <li><span>...</span></li>    
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, Model.PageCount.ToString()))">@Model.PageCount</a></li>        
            <li><a href="@(Model.Path + "?" + UrlUtility.ReplaceOrAppendQuery(Model.Query, Model.PageParameter, (Model.PageIndex + 1).ToString()))"  title="next page">>></a></li>        
            }
        }
    </ul>